<template>
  <div class="app-container">

    <el-table v-loading="loading" :data="taskListCustomList">
      <el-table-column label="客户名称" align="center" prop="cusName" />
      <el-table-column label="客户证件" align="center" prop="idCard" />
      <el-table-column label="机构" align="center" prop="orgName" />
      <el-table-column label="客户经理" align="center" prop="userName" />
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

  </div>
</template>

<script>
  import {
    listTaskInfo,
    getTaskInfo,
    delTaskInfo,
    addTaskInfo,
    updateTaskInfo,
    queryPlanNew,
    insert,
    orglist,
    queryManager,
    taskListCustom
  } from "@/api/buss/taskInfo";

  export default {
    name: "TaskInfoxq",
    components: {},
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        rwly: '',
        isShow: false,
        isShowT: false,
        // 总条数
        total: 0,
        beginDate: '',
        endDate: '',
        // 营销任务表格数据
        taskInfoList: [],
        planNameList: [],
        managervalue: '',
        orgvalue: '',
        orgList: [],
        manger: {
          orgId: ''
        },
        mangerList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        openUpdata: false,
        planNamevalue: '',
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          taskName: null,
          taskType: 0,
          ifGroup: null,
          beginDate: null,
          endDate: null,
          finishNum: null,
          userId: null,
          createTime: null,
          updateTime: null,
          createUser: null,
          updateUser: null,
          status: null,
          remark: null,
          taskTarget: null,
          orgId: null,
          complete: null,
          taskSytype: null,
          taskId: ''
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        taskListCustomList: [],
        totalxq: 0,
        taskIdS: ''
      };
    },
    created() {
      const cjZ = this.$route.query.sqBG;
      this.taskIdS = cjZ.taskId;
      this.getList();

      this.getDicts("ifGroup").then(response => {
        this.ifGroupOptions = response.data;
      });

      this.getDicts("sys_user_id").then(response => {
        this.userIdOptions = response.data;
      });

      this.getDicts("sys_org_id").then(response => {
        this.orgIdOptions = response.data;
      });
    },
    methods: {
      /** 查询营销任务列表 */
      getList() {
        this.loading = true;
        this.queryParams.taskId = this.taskIdS;
        taskListCustom(this.queryParams).then(response => {
          this.taskListCustomList = response.rows;
          this.total = response.total;
          this.loading = false;
        });

      },
      //客户经理
      orgIdBlur(mg) {
        this.manger.orgId = mg;
        queryManager(this.manger).then(response => {
          this.mangerList = response.rows;
        });
      },
      radiorwly(rwly) {
        //console.log(rwly)
        if(rwly == '1'){
          this.isShow = true;
          this.isShowT = false;
        }else{
          this.isShow = false;
          this.isShowT = true;
        }
      },
      change() {
        var bgd = this.beginDate.split("-");
        var bj = bgd.join("")
        var edb = this.endDate.split("-");
        var ej = edb.join("")
        this.addTask.beginDate = this.beginDate;
        this.addTask.endDate = this.endDate;
          console.log(bj);
        },

      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          taskId: null,
          taskName: null,
          taskType: null,
          ifGroup: null,
          beginDate: null,
          endDate: null,
          finishNum: null,
          userId: null,
          createTime: null,
          updateTime: null,
          createUser: null,
          updateUser: null,
          status: "0",
          remark: null,
          taskTarget: null,
          orgId: null,
          complete: null,
          taskSytype: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.taskId)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加营销任务";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const taskId = row.taskId || this.ids
        this.taskIdS = taskId;
        this.openUpdata = true;
        this.title = "修改营销任务";
        var yxData = {
          taskId: this.taskIdS
        }

        taskListCustom(yxData).then(response => {
          this.taskListCustomList = response.rows;
          this.totalxq = response.total;

        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["addTask"].validate(valid => {
          if (valid) {
            if (this.form.taskId != null) {
              updateTaskInfo(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              var addTaskInfo = {
                taskName: this.addTask.taskName,
                beginDateStr: this.addTask.beginDate,
                endDateStr: this.addTask.endDate,
                ifGroup: '0',
                taskType: '0',
                remark: this.addTask.remark,
                groupCode: this.planNamevalue,
                userId: '',
                orgId: '',
                taskTarget: this.taskTargetvalue,
                taskSyType: this.sybdvalue,
              }

              insert(addTaskInfo).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const taskIds = row.taskId || this.ids;
        this.$confirm('是否确认删除营销任务编号为"' + taskIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delTaskInfo(taskIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('buss/taskInfo/exportZh', {
          ...this.queryParams
        }, `总行任务导出.xlsx`)
      }
    }
  };
</script>
